#include "stdafx.h"
#include <string.h>
#include "protocol.h"

int ProtocolIsHeaderValid(unsigned char *pHeaderBuf)
{
	S_PROTOCOL_HEADER *pHeader = (S_PROTOCOL_HEADER *)pHeaderBuf;

	if (memcmp(pHeader->cMagicNum, PROTOCOL_MAGIC_NUM, sizeof(pHeader->cMagicNum)))
	{
		return (0);
	}

	if ((pHeader->eMsgNo < E_MSG_NO_MIN) || (pHeader->eMsgNo >= E_MSG_NO_MAX))
	{
		return (0);
	}

	return (1);
}

void ProtocolInitHeader(unsigned char *pMsgBuf, E_MSG_NO eMsgNo, int iMsgLen)
{
	S_PROTOCOL_HEADER *pHeader = (S_PROTOCOL_HEADER *)pMsgBuf;

	memcpy(pHeader->cMagicNum, PROTOCOL_MAGIC_NUM, sizeof(pHeader->cMagicNum));
	pHeader->iLen = iMsgLen;
	pHeader->eMsgNo = eMsgNo;
}
